import { createRouter, createWebHashHistory } from 'vue-router'

const routes=[
    {
        path:'/',
        name:'Login',
        component:()=>import('../views/login.vue')
    },
    {
        path:'/home',
        name:'Home',
        component:()=>import('../views/home.vue'),
        children:[
            {
                path:'/home/user',
                name:'User',
                component:()=>import('../components/User.vue')
            },
            {
                path:'/home/tag',
                name:'Tag',
                component:()=>import('../components/Tag.vue')
            },
            {
                path:'/home/complaint',
                name:'Complaint',
                component:()=>import('../components/Complaint.vue')
            },
            {
                path:'/home/wallpaperaudit',
                name:'WallpaperAudit',
                component:()=>import('../components/WallpaperAudit.vue')
            },
            {
                path:'home/wallpaperoperation',
                name:'WallpaperOperation',
                component:()=>import('../components/WallpaperOperation.vue')
            }
        ],
        redirect:'/home/user'
    }
]

const router=createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to,from,next)=>{
    if(to.path==='/'){
        next()
    }else{
        if(localStorage.getItem('accessToken'))next()
        else next('/')
    }
})

export default router